<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<!DOCTYPE html>
<html>
  <head>
    <title>教材吧-图书详情</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<%@ include file="/base/jsp/includeweb.jsp"%>
    <link type="text/css" rel="stylesheet" href="${path}/base/css/book.css"/>
  </head>
  
  <body>
  <%@ include file="/base/jsp/header.jsp"%>
  <%@ include file="/base/jsp/search-header.jsp"%>
  <div id="content-wrapper" class="content-wrapper clear">
     <div class="book-left clear">
         <%@ include file="/base/jsp/book-type-nav.jsp"%>
         <%@ include file="/base/jsp/hot-books.jsp"%>
     </div>
     
     <div class="book-types-content book-detail-content clear">
         <div id="book-info" class="clear">
             <div class="book-info-fisrt">
                 <div class="img clear"><img/></div>
                 <div class="text clear">
                 <p class="name" name="name"></p>
                 <p class="desc" name="desc"></p>
                 <p class="price-now" name="price-now">教材吧价：￥<span></span></p>
                 <p class="price-pre" name="price-pre">定&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;价：￥<span></span></p>
                 <p class="reportory" name="reportory">库&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;存：<span></span>&nbsp;本</p>
                 <p class="recommend" name="recommend">推荐指数：
                 </p>
                 </div>
                 <div class="text">
                 <p class="author" name="author">作者：<span></span></p>
                 <p class="publisher" name="publisher">出版社：<span></span></p>
                 <p class="pub-time" name="pub-time">出版时间：<span></span></p>
                 <p class="pub-version" name="pub-version">版本号：<span></span></p>
                 </div>
                 <div class="buy-num">
                     <input name="bid" id="bid" type="text" class="hide"/>
                     <div class="buy-num-wrapper clear">
                     <span class="buy-num-text">我要买</span>
                      <img id="buy-num-minus" src="${path}/base/img/minus-but.png"/>
                      <input id="number" name="number" type="text" value="1"/>
                      <img id="buy-num-plus" src="${path}/base/img/plus-but.png"/>
                      <span class="buy-num-text">本</span>
                     </div>                                           
                 </div>
                 <div class="buy-but-wrapper">
                     <input id="cart-but" type="button" value="加入购物车"/>
                     <input id="buy-but" type="button" value="一键购买"/>
                 </div>
             </div>
             
         </div>
         <!--图书基本信息介绍完毕-->
         <div id="recommend-info">
            <h2>最佳组合</h2>
            <div class="recommend-info-content clear">
              
                
              
                
            </div>
         
         </div>
         
         <div id="book-detail-info">
          <h2>商品详情</h2>
            <div class="detail-info-content clear">
            <div class="detail-info-eight clear">
            <div name="edition">版次：<span></span></div><div name="page">页数：<span></span></div>
            <div name="print-time">印刷时间：<span></span></div><div name="paper">纸张：<span></span></div>
            <div name="print-count">印次：<span></span></div><div name="package">包装：<span></span></div>
            </div>
            <h3>教材吧推荐</h3>
            <p class="abstract">
            </p>
            <h3>目录</h3>
           <p class="catalog">
           </p>
            </div>
         </div>
     </div>
  </div>
  <%@ include file="/base/jsp/footer.jsp"%>
  </body>
  <script type="text/javascript">
  var bid = getParameter("id");
  var nump = /^\d+$/;
  var userid = "${sessionScope.userid}";
  var school = '';
  var scode = '';
  var depart = '';
  var dcode = '';
  var major = '';
  var mcode = '';
  var yearCode = '';
  $(function(){
    $("input[name=bid]").val(bid);
    //获取图书详情
	request("findByIdBook.do","id="+bid,function(data){
		$(".name").text(data.name);
		$(".desc").text(data.description);
		$(".img img").attr("src",getImg(data.img));
		$(".price-now").find("span").text(data.priceSelling);
		$(".price-pre").find("span").text(data.priceOriginal);
		$(".reportory").find("span").text(data.reportory);
		for(var i = 0 ; i < data.rate ; i++){
		    var img = $('<img src="${path}/base/img/star.png"/>');
		    $(".recommend").append(img);
		}
		$(".author").find("span").text(data.author);
		$(".publisher").find("span").text(data.publisher);
		$(".pub-time").find("span").text($.formatDate("yyyy-MM-dd",data.timePublish));
		$(".pub-version").find("span").text(data.version);
		$("div[name=edition]").find("span").eq(0).text(data.version);
		$("div[name=page]").find("span").text(data.pagecount);
		$("div[name=wordc]").find("span").text(data.wordcount);
		$("div[name=print-time]").find("span").text($.formatDate("yyyy-MM-dd",data.printDate));
		$("div[name=format]").find("span").text(data.booksize);
		$("div[name=paper]").find("span").text(data.paper);
		$("div[name=print-count]").find("span").text(data.printTime);
		$("div[name=package]").find("span").text(data.pack);
		$(".abstract").html(data.description);
		$(".catalog").html(data.directory);
		var codes = data.ctCodeList[0];
		scode = codes.schoolCode;
		dcode = codes.departmentCode;
		mcode = codes.majorCode;
		yearCode = codes.yearCode;
		//获取最佳组合图书
		var queryBooks = "schoolCode="+scode+"&departmentCode="+dcode+"&majorCode="+mcode+"&yearCode="+yearCode+"&pageIndex=0&pageSize=4";
		request("listBook.do",queryBooks,function(data){
		      var d = data.data;
		      for(var i = 0; i < d.length ; i++){
		          var brow = $('<div class="recommend-book-wrapper">'
		      +'<a class="recommend-book-a" target="_blank"><img/></a><div class="price"></div>'
		      +'<div class="name"><a target="_blank"></a></div><input name="recommend-book" type="checkbox"/></div>');
		      var plus = $('<div class="book-plus"></div>');
		      var input = $('<input id="buy-recommend-but" type="button" value="快速购买"/>');
		          var book = d[i];
		          brow.attr("id",book.id);
		          brow.find(".recommend-book-a img").attr("src",getImg(book.img));
		          brow.find(".recommend-book-a").attr("href","bookdetail.do?id="+book.id);
		          brow.find(".name a").attr("href","bookdetail.do?id="+book.id);
		          brow.find(".name a").text(book.name);
		          brow.find(".price").text("￥"+book.priceSelling);
		          $(".recommend-info-content").append(brow);
		          if(i != d.length -1){
		              $(".recommend-info-content").append(plus);
		          }
		      }
		      if(d.length >　0){
		          $(".recommend-info-content").append(input);
		      }
		      $("#buy-recommend-but").click(function(){
                  if(!isDefine(userid)){
                     alert("请先登录");
                     location.href = "weblogin.do";
                     return;
                  }
                  var arr = new Array();
                  if($("input[name=recommend-book]:checked").length < 1){
                      alert("请至少选择一本书");
                      return;
                  }
                  $("input[name=recommend-book]:checked").each(function(){
                     arr.push($(this).parent(".recommend-book-wrapper").attr("id"));
                  })
                  var bookids = arr.join(",");
                  location.href="webaddorder.do?userid="+userid+"&bookid="+bookids+"&count=1&type=2";
               });
		 });
	});
     
    
     
     $("#buy-num-minus").click(function(){
         var num = parseInt($("#number").val());
         if(nump.test(num)==false){
            alert("请输入正确的数字格式");
            return;
         }
         if(num > 0){
             $("#number").val(num-1);
         }
     })
     
       
     $("#buy-num-plus").click(function(){
         var num = parseInt($("#number").val());
         if(nump.test(num)==false){
            alert("请输入正确的数字格式");
            return;
         }
         $("#number").val(num+1);
     })
     
     $("#cart-but").click(function(){
         if(!isDefine(userid)){
                alert("请先登录");
                location.href = "weblogin.do";
                return;
           }
          if(confirm("确定要加入购物车么？")){
              var bookid = $(this).parents(".search-book-wrapper").attr("id");
              request("saveCart.do","userid="+userid+"&bookid="+bid+"&count=1",function(data){
                 if(data.success==true){
                    alert("添加成功");
                 }else{
                    alert("添加失败");
                 }
              });
          }
     })
     
     $("#buy-but").click(function(){
          if(!isDefine(userid)){
                alert("请先登录");
                location.href = "weblogin.do";
                return;
           }
         var num = parseInt($("#number").val());
         if(nump.test(num)==false || num <= 0){
             alert("请选择合适的数目");
             return;
         }
         location.href="webaddorder.do?userid="+userid+"&bookid="+$("input[name=bid]").val()+"&count="+num+"&type=1&isM=1";
     })
     
     
  })
  
  
  
  </script>
</html>